package com.tourism.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tourism.dao.AttractionDao;
import com.tourism.entity.Attraction;
import com.tourism.entity.AttractionQuery;
import com.tourism.service.AttractionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @Description
 * @Author z
 * @Date 2021-03-01 21:05
 */
@Service
public class AttractionServiceImpl implements AttractionService {

    @Autowired
    private AttractionDao attractionDao;


    @Override
    public Attraction getAttractionById(Long id) {
        Attraction attraction = attractionDao.getAttractionById(id);
        return attraction;
    }
//    根据ID删除景点
    @Override
    public Boolean deleteAttractionById(long id) {
        return attractionDao.deleteAttractionById(id);
    }

//新增景点
    @Override
    public boolean addAttraction(Attraction attraction) {
        attraction.init();
        return attractionDao.addAttraction(attraction);
    }
//修改景点
    @Override
    public boolean updateAttraction(Attraction attraction) {
        return attractionDao.updateAttraction(attraction);
    }
//更新浏览量
    @Override
    public boolean updatePageView(Long id) {
        return attractionDao.updatePageView(id);
    }

//分页查询景点
    @Override
    public PageInfo<Attraction> getAttractionList(AttractionQuery attractionQuery) {
//        作用得到页数，页码
        PageHelper.startPage(attractionQuery.getPageNum(), attractionQuery.getPageSize());
//      多条件模糊查询
        List<Attraction> AttractionList = attractionDao.getAttractionList(attractionQuery);
//查询到的列表作用
        PageInfo<Attraction> result = new PageInfo<>(AttractionList);
        return result;
    }


}
